import React from 'react'
import moment from 'moment'
import { Form, Button, Input, Row, Col, Modal, Drawer, DatePicker, message } from 'antd';
const { RangePicker } = DatePicker;
export default class Index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            pageIndex: 1,
            pageSize: 10
        }
    }
    onFinish = (value) => {
        let page = {
            pageIndex: this.state.pageIndex - 1,
            pageSize: this.state.pageSize
        }
        let time = {
            startTime:
                value.warningTime == undefined
                    ? ""
                    : new Date(value.warningTime[0]._d).getTime(),
            endTime:
                value.warningTime == undefined
                    ? ""
                    : new Date(value.warningTime[1]._d).getTime(),
        };
        let values = {
            ...value,
            ...page,
            ...time
        }
        if ((values.startTime === undefined || values.startTime === "") && (values.endTime == undefined || values.endTime == "")) {
            message.warning("请输入查询条件！", 3);
            return
        } else if (values.startTime === "" && values.endTime === "") {
            message.warning("请输入查询条件！", 3);
        }
        if (values.startTime === "") {
            values.startTime = undefined
        }
        if (values.endTime === "") {
            values.endTime = undefined
        }
        this.props.handleQueryByAdress(values)
    }
    render() {
        return (
            <Form layout="inline" onFinish={this.onFinish} ref="queryByAdress">
                <Form.Item
                    name="warningTime"
                    // label="请选择日期"
                    style={{ float: 'left' }}
                >
                    <RangePicker
                        placeholder={['开始时间', '结束时间']}
                        showTime={{ defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')] }}
                        format="YYYY-MM-DD"
                    />
                </Form.Item>
                <Form.Item>
                    <Button type="primary" htmlType="submit">查询</Button>
                </Form.Item>
                <Form.Item>
                    <Button onClick={() => {
                        this.refs.queryByAdress.resetFields();
                        this.props.handleResetQuery();
                    }} >重置</Button>
                </Form.Item>

            </Form>
        )
    }
}